package com.hlk.singleton;

import java.lang.reflect.Constructor;

/**
 * @author hlk
 * @version 1.0
 * @date 2020-11-26 9:41
 */
public class Test {

    public static void main(String[] args) throws Exception {
        // 测试反射对单例的破坏
//        Class<HungrySingleton> clazz = HungrySingleton.class;
//        Constructor<HungrySingleton> constructor = clazz.getDeclaredConstructor();
//        constructor.setAccessible(true);
//
//        HungrySingleton instance = HungrySingleton.getInstance();
//        HungrySingleton newInstance = constructor.newInstance();
//        System.out.println(instance);
//        System.out.println(newInstance);
//
//        System.out.println(instance == newInstance);

        // 枚举单例测试
        EnumSingleton.getInstance().printTest();
    }


}
